/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import dao.ulti.HibernateUtil;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import pojo.Category;

/**
 *
 * @author Nero
 */
public class CategoryDAO extends AbstractDAO<Category, String> {

    @Override
    protected Class getPOJOClass() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public static List<Category> getCategoryList() {
        Session session = HibernateUtil.getSessionFactory().openSession();
        String hql = "FROM Category p WHERE p.isDelete = :IS_DELETE ORDER BY p.name asc";
        Query query = session.createQuery(hql);
        query.setParameter("IS_DELETE", false);
        List<Category> categoryList = query.list();
        session.close();
        return categoryList;
    }
    
    public Category getCategory(long id) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        String hql = "FROM Category c WHERE c.id = :ID";
        Query query = session.createQuery(hql);
        query.setParameter("ID", id);
        if (!query.list().isEmpty()) {
            Category category = (Category) query.uniqueResult();
            return category;
        } else {
            return null;
        }
    }
    /*
     public List<Manufacturer> getProductList() {
     Session session = HibernateUtil.getSessionFactory().openSession();
     String hql = "FROM Product p WHERE p.isDelete = :IS_DELETE";
     Query query = session.createQuery(hql);
     query.setParameter("IS_DELETE", false);
     List<Product> productList = query.list();
     return productList;
     }
     */
}